package com.gzx.qc.modular.check.mapper;

import com.gzx.qc.modular.check.entity.GzxCallCheck;
import com.gzx.qc.modular.check.vo.GzxCallCheckVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * @author zjt
 * @description
 * @since 2025/7/29 18:04
 */
public interface GzxCallCheckMapper extends BaseMapperPlus<GzxCallCheck, GzxCallCheckVo> {

    /**
     * 批量保存
     *
     * @param sql
     */
    @Insert("<script>insert ignore into gzx_call_check (id, call_id, call_type, callee,call_duration, agent_num, user_name, dept_id, file_url, keyword) " +
            "VALUES ${sql}" +
            "</script>")
    void insertBatch(String sql);

    /**
     * 补全关键词
     *
     * @param callCheckList
     */
    @Update("<script>" +
            "update gzx_call_check " +
            "set keyword = CASE call_id " +
            "<foreach collection='callCheckList' item='item' separator=''>" +
            "WHEN #{item.callId} THEN #{item.keyword}" +
            "</foreach> " +
            "END " +
            "WHERE call_id IN " +
            "<foreach collection='callCheckList' item='item' open='(' separator=',' close=')'>" +
            "#{item.callId}" +
            "</foreach>" +
            "</script>")
    void completionCheckKeyword(List<GzxCallCheck> callCheckList);

    /**
     * AI审核状态
     *
     * @param callCheckList
     */
    @Update("<script>" +
            "update gzx_call_check " +
            "set ai_review_status = CASE id " +
            "<foreach collection='callCheckList' item='item' separator=''>" +
            "WHEN #{item.id} THEN #{item.aiReviewStatus}" +
            "</foreach> " +
            "END," +
            "ai_review_result = CASE id " +
            "<foreach collection='callCheckList' item='item' separator=''>" +
            "WHEN #{item.id} THEN #{item.aiReviewResult}" +
            "</foreach> " +
            "END " +
            "WHERE id IN " +
            "<foreach collection='callCheckList' item='item' open='(' separator=',' close=')'>" +
            "#{item.id}" +
            "</foreach>" +
            "</script>")
    void modifyAiReviewStatus(List<GzxCallCheck> callCheckList);
}
